package com.example.mq2.mqserver.core;

import com.fasterxml.jackson.databind.ser.std.ObjectArraySerializer;

import java.io.Serializable;
import java.util.UUID;

public class Message implements Serializable {

    private BasicProperties basicProperties = new BasicProperties();
    private byte[] body;

    //起终偏移量
    private transient long offsetBeg;
    private transient long offsetEnd;

    //当前信息是否有效(硬盘数据采用逻辑删除, 0x0 表示无效，0x1 表示有效)，
    private byte isValid = 0x1;

    public static Message createMessageWithId(String routingKey, BasicProperties basicProperties, byte[] body) {
        Message message = new Message();
        if(basicProperties != null) {
            message.setBasicProperties(basicProperties);
        }
        message.setMessageId("M-" + UUID.randomUUID().toString());
        message.setRoutingKey(routingKey);
        message.setBody(body);
        return message;
    }

    public void setMessageId(String messageId) {
        basicProperties.setMessageId(messageId);
    }

    public void setRoutingKey(String routingKey) {
        basicProperties.setRoutingKey(routingKey);
    }

    public void setDeliverMode(int deliverMode) {
        basicProperties.setDeliverMode(deliverMode);
    }

    public String getMessageId() {
        return basicProperties.getMessageId();
    }

    public String getRoutingKey() {
        return basicProperties.getRoutingKey();
    }

    public int getDeliverMode() {
        return basicProperties.getDeliverMode();
    }



    public BasicProperties getBasicProperties() {
        return basicProperties;
    }

    public void setBasicProperties(BasicProperties basicProperties) {
        this.basicProperties = basicProperties;
    }

    public byte[] getBody() {
        return body;
    }

    public void setBody(byte[] body) {
        this.body = body;
    }

    public long getOffsetBeg() {
        return offsetBeg;
    }

    public void setOffsetBeg(long offsetBeg) {
        this.offsetBeg = offsetBeg;
    }

    public long getOffsetEnd() {
        return offsetEnd;
    }

    public void setOffsetEnd(long offsetEnd) {
        this.offsetEnd = offsetEnd;
    }

    public byte getIsValid() {
        return isValid;
    }

    public void setIsValid(byte isValid) {
        this.isValid = isValid;
    }
}
